package sg.tua.hud;

import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.geom.Transform;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;

public class HudAnimation implements ICollideable, IHudAnimation {

	protected String name;
	protected Vector2f position;
	protected Animation animation;
	protected Shape collisionShape;
	protected int collisionType;
	
	public HudAnimation(String name, Vector2f position, Animation animation, Shape collisionShape, int collisionType){
		this.name = name;
		this.animation = animation;
		this.position = position;
		this.collisionShape = collisionShape;
		this.collisionType = collisionType;
	}
	@Override
	public Shape getCollisionShape() {
		//return collisionShape.transform(Transform.createTranslateTransform(position.x, position.y));
		Rectangle newShape = new Rectangle(collisionShape.getX(),collisionShape.getY(),collisionShape.getWidth(),collisionShape.getHeight());
		newShape.setCenterX(position.x);
		newShape.setCenterY(position.y);
		return newShape;
	}

	@Override
	public int getCollisionType() {
		// TODO Auto-generated method stub
		return collisionType;
	}

	@Override
	public Shape getNormalCollisionShape() {
		// TODO Auto-generated method stub
		return collisionShape;
	}

	@Override
	public boolean isCollidingWith(ICollideable collidable) {
		return this.getCollisionShape().intersects(collidable.getCollisionShape());
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public Vector2f getPosition() {
		return position;
	}

	@Override
	public void render(Graphics g) {
		animation.draw(position.x, position.y);
		//g.draw(this.getCollisionShape());
	}

	@Override
	public void setPosition(Vector2f position) {
		this.position = position;

	}

	@Override
	public void update(GameContainer gc, StateBasedGame sb, int delta) {
		animation.update(delta);
	}

}
